export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
      queryParams: {
        pageIndex: 1,
        pageSize: 20,
      },
    }
  },
  created() {
    this.queryList(true)
  },
  methods: {
    queryList(reload = false) {
      if (reload) {
        this.loading = false
        this.finished = true
        this.queryParams.pageIndex = 1
        this.refreshing = false
      }
      this.ajaxData &&
        this.ajaxData(this.queryParams)
          .then((res) => {
            if (reload) {
              this.finished = false
            }
            this.loading = false
            if (res.result == 1) {
              let list = res.dataList || []
              if (reload) {
                this.list = list
              } else {
                this.list = this.list.concat(list)
              }
              if (list.length < this.queryParams.pageSize) {
                this.finished = true
              }
              this.queryParams.pageIndex++
            } else {
              this.loading = false
              this.finished = true
              this.$toast.fail(res.msg)
            }
          })
          .catch(() => {
            this.loading = false
            this.finished = true
            this.$toast.fail('请求失败')
          })
    },
    // 重新开始请求
    reloadList() {
      this.finished = false
      this.loading = true
      this.queryList(true)
    },
  },
}
